import 'package:flutter/material.dart';
import 'package:flutter_smart_heating/ui/ui.dart';
import 'package:get/get.dart';

import '../logic.dart';
import '../state.dart';

class SearchTabbarView extends StatelessWidget {
  const SearchTabbarView({
    super.key,
    required this.state,
    required this.logic,
  });

  final SearchState state;
  final SearchLogic logic;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: UiTheme(context).match(light: Colors.white),
      height: 45,
      child: GetBuilder<SearchLogic>(
        id: 'category',
        builder: (_) {
          return state.category.isEmpty
              ? Container()
              : TabBar(
                  dividerHeight: 0,
                  labelColor: UiTheme.primary,
                  indicator: const UiRoundUnderlineTabIndicator(
                    lineWidth: 30,
                    borderSide: BorderSide(color: UiTheme.primary, width: 3),
                  ),
                  indicatorColor: UiTheme.primary,
                  unselectedLabelColor: UiTheme.of(context)
                      .match(light: Colors.black, dark: Colors.white)
                      .withOpacity(0.65),
                  unselectedLabelStyle: const TextStyle(
                    fontWeight: FontWeight.normal,
                  ),
                  labelStyle: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: UiTheme.fontSize.tabbarFontSize,
                  ),
                  controller: state.tabController,
                  tabs: state.category
                      .map((e) => Tab(
                            text: e['name'],
                          ))
                      .toList(),
                  onTap: (value) {
                    logic.onTabsClick(value);
                  },
                );
        },
      ),
    );
  }
}
